<#assign module="financial"/>

<@override name="header">
<link rel="stylesheet" href="${ctx}/assets/css/datetimepicker.css">
</@override>
<@override name="body">
<div class="row">
	<div class="col-xs-10">
	  	<div class="btn-group">
		  <a class="btn btn-default active" href="${ctx}/financialrecord/list">财务明细（根据订单公司）</a>
		  <a class="btn btn-default" href="${ctx}/financialrecord/listByDriver">财务明细（根据服务人员公司）</a>
		  <a class="btn btn-default" href="${ctx}/financialrecord/driverlist">服务人员预存款</a>
		  <a class="btn btn-default" href="${ctx}/financialrecord/memberlist">客户预存款</a>
		  <a class="btn btn-default" href="${ctx}/financialrecord/driverrechargelist">服务人员充值记录</a>
		  <a class="btn btn-default" href="${ctx}/financialrecord/memberrechargelist">客户账户明细</a>
		</div>
	</div>
	
 	<div class="col-xs-2">
 		<@shiro.hasPermission name='financialadd'>
 			<button class="pull-right btn btn-primary" onclick="window.location='${ctx}/financialrecord/add';"><i class="icon-plus"></i>&nbsp;添加</button>
		</@shiro.hasPermission>
 			<button class="pull-right btn btn-primary btn-primary-a" onclick="window.location='${ctx}/financialrecord/exportList?companyId=${companyId?if_exists}&param=${param?if_exists}&thisbtn=${thisbtn?if_exists}&ftype=${ftype?if_exists}&startTime=${startTime?if_exists}&endTime=${endTime?if_exists}';"><i class="glyphicon glyphicon-share-alt"></i>&nbsp;导出</button>
	</div>
</div>

<div class="row margin-top">
	<div class="col-xs-12">
		<form class="form-inline" role="form">
			<@shiro.isMainCompany>
				<select class="form-control" name="companyId" id="companyId">
					<option value="">全部公司</option>
		  			<#list companys as company>
		  				<option value="${company.id}" <#if companyId?? && companyId==company.id>selected="selected"</#if>>${company.abbreviation}</option>
		  			</#list>
	  			</select>
			</@shiro.isMainCompany>
			<div class="form-group">
				<select class="form-control" data-val="true"  name="ftype">
					<option value="0" <#if ftype==0>selected="selected"</#if> >全部金额</option>
					<option value="1"<#if ftype==1>selected="selected"</#if> >收入金额</option>
					<option value="2" <#if ftype==2>selected="selected"</#if>>支出金额</option>
				</select>
		    </div>
		    
		    <div class="input-group">
				<input id="startTime" name="startTime" type="text" class="form-control" placeholder="开始时间" value="${startTime?if_exists}" />
			</div>
			
		  	<div class="form-group">
		  		<input id="endTime" name="endTime" type="text" class="form-control" placeholder="结束时间" value="${endTime?if_exists}" />
		    </div>
		    
		  	<div class="form-group">
		  		<input type="text" class="form-control" style="width:250px;" name="param" value="${param?if_exists}" placeholder="输入流水号、对象、备注">
		  	</div>
		  	<button id="search_button" type="submit" class="btn btn-primary"><i class="icon-search"></i>&nbsp;搜索</button>
		</form>
	</div>
</div>

<div class="row margin-top">
	<div style="float:right;margin-right:15px;">
		<#if thisbtn?? || startTime?? || endTime ?? || param?? >
		<div class="btn-group" style="margin-left:10px;">
			<p class="form-control-static"><span style="color:#394249; font-weight:700;" class="btn btn-default btn-sm">本次搜索收入：${page.nowMoney}</span></p>
		</div>
		</#if>
		<div class="btn-group" style="margin-left:10px;">
			<p class="form-control-static"><a href="${ctx}/financialrecord/list?thisbtn=allTotal"><span style="font-weight:700;background-color:#394249;" <#if (thisbtn)??  && thisbtn=="allTotal">class="btn btn-success btn-sm" <#else>class="btn btn-info btn-sm"</#if>>全部收入：${page.allTotal}</span></a></p>
		</div>
		<div class="btn-group" style="margin-left:10px;">
			<p class="form-control-static"><a href="${ctx}/financialrecord/list?thisbtn=thisYearTotal"><span style="font-weight:700;background-color:#394249;" <#if (thisbtn)??  && thisbtn=="thisYearTotal">class="btn btn-success btn-sm" <#else>class="btn btn-info btn-sm"</#if>>本年收入：${page.thisYearTotal}</span></a></p>
		</div>
		<div class="btn-group" style="margin-left:10px;">
			<p class="form-control-static"><a href="${ctx}/financialrecord/list?thisbtn=thisMonthTotal"><span style="font-weight:700;background-color:#394249;" <#if (thisbtn)??  && thisbtn=="thisMonthTotal">class="btn btn-success btn-sm" <#else>class="btn btn-info btn-sm"</#if>>本月收入：${page.thisMonthTotal}</span></a></p>
		</div>
		<div class="btn-group" style="margin-left:10px;">
			<p class="form-control-static"><a href="${ctx}/financialrecord/list?thisbtn=lastDayTotal"><span style="font-weight:700;background-color:#394249;" <#if (thisbtn)??  && thisbtn=="lastDayTotal">class="btn btn-success btn-sm" <#else>class="btn btn-info btn-sm"</#if>>昨日收入：${page.lastDayTotal}</span></a></p>
		</div>
		<div class="btn-group" style="margin-left:10px;">
			<p class="form-control-static"><a href="${ctx}/financialrecord/list?thisbtn=thisDayTotal"><span style="font-weight:700;background-color:#394249;" <#if (thisbtn)??  && thisbtn=="thisDayTotal">class="btn btn-success btn-sm" <#else>class="btn btn-info btn-sm"</#if>>今日收入：${page.thisDayTotal}</span></a></p>
		</div>
	</div>
</div>

<div class="row margin-top">
	<div class="col-xs-12">
	<div class="panel panel-primary">
	<div class="table-responsive">
		<table class="table table-hover table-striped">
			<thead>
			<tr style="font-size:14px;">
				<th>状态</th>
				<th>流水号</th>
				<th>金额</th>
				<th>对象</th>
				<@shiro.isMainCompany>
				<th>公司</th>
				</@shiro.isMainCompany>
				<th>时间</th>
				<th>备注</th>
				<th>操作</th>
			</tr>
			</thead>
			<tbody>
				<#if (page.content)?? >
			  	<#list page.content as data>
					<tr>
						<td>
							<#if data.status==1>
								<span class="label label-success">已审</span>
							<#else>
								<span class="label label-danger">待审</span>
							</#if>
						</td>
						<td>${data.code}</td>
						<td <#if (data.money>0)>style="color:green;font-weight:700;"<#elseif (data.money<0)>style="color:red;font-weight:700;"</#if>>
							${data.money}
						</td>
						<td>${data.who}</td>
						<@shiro.isMainCompany>
						<td>${data.orderCompanyName!data.companyName}</td>
						</@shiro.isMainCompany>
						<td>${data.created?string('yyyy/MM/dd HH:mm')}</td>
						<td style="max-width:500px;">${data.memo?if_exists}</td>
						<td>
							<@shiro.hasPermission name='financialdelete'>
								<a href="javascript:;" data-value="${data.id}" class="btn-link deletethis">删除</a>
							</@shiro.hasPermission>
							<#if data.status!=1>
								<@shiro.hasPermission name='financialaudit'>
									<a href="javascript:;" data-value="${data.id}" data-money="${data.money}" class="btn-link auditthis">审核</a>
								</@shiro.hasPermission>
							</#if>
						</td>
					</tr>
				</#list>
				</#if>
			</tbody>
		</table>
		<#if page.totalElements??>
		<ul class="pagination pull-right pagination-sm">
			<li><a>共 ${page.totalElements} 条数据</a></li>
			<@pg.pager items=page.totalElements?number maxPageItems=20 export="currentPageNumber=pageNumber" url="${ctx}/financialrecord/list">
				<@pg.param name="companyId" value="${companyId?if_exists}"/>
				<@pg.param name="param" value="${param?if_exists}"/>
				<@pg.param name="ftype" value="${ftype?if_exists}"/>
				<@pg.param name="startTime" value="${startTime?if_exists}"/>
				<@pg.param name="endTime" value="${endTime?if_exists}"/>
				<@pg.param name="thisbtn" value="${thisbtn?if_exists}"/>
				<@pg.index>
					<@pg.first>
						<li><a href="${pageUrl}">&laquo;</a></li>
					</@pg.first>
					<@pg.prev>
						<li><a href="${pageUrl}">&lsaquo;</a></li>
					</@pg.prev>
					<@pg.pages>
						<#if  currentPageNumber == pageNumber >
							<li class="active"><a href="#">${pageNumber}</a></li>
						<#else>
							<li><a href="${pageUrl}">${pageNumber}</a></li>
						</#if>
					</@pg.pages>
					<@pg.next>
						<li><a href="${pageUrl}">&rsaquo;</a></li>
					</@pg.next>
					<@pg.last>
						<li><a href="${pageUrl}">&raquo;</a></li>
					</@pg.last>
				</@pg.index>
			</@pg.pager>
		</ul>
		</#if>
	</div>
	</div>
	</div>
</div>

<form class="form-horizontal" method="post">
	<div class="modal fade" id="dialog_audit">
	  <div class="modal-dialog">
	    <div class="modal-content">
	      <div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
	        <h4 class="modal-title">确认要审核通过吗</h4>
	      </div>
	      <div class="modal-body">
	      	<input type="hidden" name="id" id="dialog_audit_id">
	      	<div class="form-group">
	            <div class="col-sm-10">
	                	金额：
	                	<input type="text" class="form-control" id="dialog_audit_money" name="money" required/>
	                	<span style="color:red;">审核通过后，将给服务人员余额里面加上相应金额！</span>
	            </div>
	        </div>
	      </div>
	      <div class="modal-footer">
	    	<button type="button" class="btn btn-primary" id="ok_modal_audit" action="${ctx}/financialrecord/audit">提交</button>
	    	<button type="button" class="btn btn-default" id="close_modal_audit">关闭</button>
	      </div>
	    </div><!-- /.modal-content -->
	  </div><!-- /.modal-dialog -->
	</div>
</form>
		
</@override>
<@override name="footer">
	<script type="text/javascript">
		window.daijia = {
			ctx:'${ctx}',
			userId:'<@shiro.principal property='id'/>'
		};
	</script>
	<script src="${ctx}/assets/js/pushmessage.js"></script>
	<script src="${ctx}/assets/js/bootstrap-datetimepicker.min.js"></script>
	<script src="${ctx}/assets/js/bootstrap-datetimepicker.zh-CN.js"></script>
	<script type="text/javascript">
		var thisButton;
		function deleteFinancialRecord() {
		    $.post('${ctx}/financialrecord/delete',{'id':thisButton.attr("data-value")},function(data){
		            if(data.success){
		            	thisButton.parent().parent().remove();
		                $.scojs_message('财务记录删除成功', $.scojs_message.TYPE_OK);
		            } else {
		                $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
		            }
		    },'json');
		}
		$(document).ready(function(){
		
			$("#startTime").datetimepicker({
		        format: "yyyy-mm-dd HH:ii",
		        language: 'zh-CN',
		        showMeridian: true,
		        autoclose: true,
		        todayBtn: true
		    });
			$("#endTime").datetimepicker({
				format: "yyyy-mm-dd HH:ii",
		        language: 'zh-CN',
		        showMeridian: true,
		        autoclose: true,
		        todayBtn: true
		    });
		
		    $(".deletethis").click(function(){
		          thisButton = $(this);
		          var confirm = $.scojs_confirm({
		            content: "你真的要删除该财务记录吗？",
		            action:deleteFinancialRecord
		          });
		          confirm.show();
		    });
		    
		    //审核
			$(".auditthis").click(function(){
		    	thisButton = $(this);
		    	$("#dialog_audit_id").val(thisButton.attr("data-value"));
		    	$("#dialog_audit_money").val(thisButton.attr("data-money"));
		    	$("#ok_modal_audit").attr("disabled",false);
		    	$('#dialog_audit').modal();
		    });
			$("#close_modal_audit").click(function(){
				$('#dialog_audit').modal("hide");
			});
			$("#ok_modal_audit").click(function(){
				$(this).attr("disabled",true);
				var money=$("#dialog_audit_money").val();
				var reg=/^(-?\d+)(.[0-9]{0,2})?$/;
				if(!reg.test(money)){
			       $.scojs_message('无效的金额，金额必须为数字', $.scojs_message.TYPE_ERROR);
			       $("#ok_modal_audit").attr("disabled",false);
			       return;
			    }
				$.post($(this).attr("action"),{'id':thisButton.attr("data-value"),'money':money},function(data){
		            if(data.success){
		            	$.scojs_message("审核完成", $.scojs_message.TYPE_OK);
		            	window.location.reload(true);
		            }
		            else{
		            	$("#ok_modal_audit").attr("disabled",false);
		            	$.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
		            }
				},'json');
			});
		});
		$(".btn-info").mouseover(function(){
	    	if($(this).hasClass("btn-info")){
	    		$(this).removeClass("btn-info").addClass("btn-success");
	    	}
    	 });
		$(".btn-info").mouseout(function(){
	    		$(this).removeClass("btn-success").addClass("btn-info");
    	 });
    	 $('#endTime').change(function(){
			  var begin=new Date($('#startTime').val().replace(/-/g,"/"));
		      var end=new Date($('#endTime').val().replace(/-/g,"/"));
		   	   if(begin!=null&&end!=null&&begin-end>=0){
	  				 $('#endTime').val("");
	  				 $.scojs_message("截止日期要在开始日期之后!", $.scojs_message.TYPE_ERROR);
		      	}
	 	});
	 	 $('#startTime').change(function(){
			  var begin=new Date($('#startTime').val().replace(/-/g,"/"));
		      var end=new Date($('#endTime').val().replace(/-/g,"/"));
		   	   if(begin!=null&&end!=null&&begin-end>=0){
	  				 $('#endTime').val("");
	  				 $.scojs_message("开始日期要在截止日期之前!", $.scojs_message.TYPE_ERROR);
		      	}
		 });
    	 
	</script>
</@override>
<@extends name="../layout.ftl"/>